#include "msgqueue.h"

CMsgQueue::CMsgQueue(void)
{

}

CMsgQueue::~CMsgQueue(void)
{

}

void CMsgQueue::Push(IMsg* pMessage)
{
	c_assert(pMessage != NULL);
	SYNC_OBJ(this);
	pMessage->AddRef();
	m_Queue.push(pMessage);
}

bool CMsgQueue::GetNext(IMsg** ppMessage)
{
	SYNC_OBJ(this);
	*ppMessage = m_Queue.front();
	return true;
}

bool CMsgQueue::IsEmpty()
{
	SYNC_OBJ(this);
	return m_Queue.empty();
}

void CMsgQueue::Clear()
{
	SYNC_OBJ(this);
	_lComPtr<IMsg> pMessage;
	while (GetNext((IMsg**)&pMessage)) {
		pMessage.dispose();
	}
}

void CMsgQueue::PostSem()
{
	this->m_sem.Post();
}
void CMsgQueue::WaitSem()
{
	this->m_sem.Wait();
}

